package org.easy.web.api.file;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.easy.file.model.FileModel;
import org.easy.tool.res.Result;
import org.easy.web.service.file.FileMonitorService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 文件监控器接口
 * @Author: wxl
 * @CreateTime: 2022/12/28 8:44
 */
@Api(value = "文件监控API",tags = "文件监控API")
@RestController
@RequestMapping("/api/file/")
public class EasyFileController {

    private final FileMonitorService fileMonitorService;

    public EasyFileController(FileMonitorService fileMonitorService) {
        this.fileMonitorService = fileMonitorService;
    }

    @ApiOperation(value = "根据文件路径开启监控任务",httpMethod = "POST")
    @ApiImplicitParam(name = "filePath",value = "文件路径",required = true,dataTypeClass = String.class)
    @PostMapping("startFileMonitorTask")
    public Result<?> startFileMonitorTask(String filePath){
        return fileMonitorService.startFileMonitor(filePath);
    }

    @ApiOperation(value = "根据文件路径停止监控任务",httpMethod = "POST")
    @ApiImplicitParam(name = "filePath",value = "文件路径",required = true)
    @PostMapping("stopFileMonitorTask")
    public Result<Boolean> stopFileMonitorTask(String filePath){
        return fileMonitorService.stopFileMonitor(filePath);
    }

    @ApiOperation(value = "获取所有开启监控任务",httpMethod = "GET")
    @GetMapping("getFileTaskList")
    public Result<List<FileModel>> getFileTaskList() {
        return fileMonitorService.queryFileTaskList();
    }

}
